home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 May
/
EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso
/
softwareupdate
/
system
/
amigados
/
amigadoslibrary
/
fgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-10
|
1KB
|
55 lines
/* FGets.c V1.1 93-03-03 */
/* ROM library: "dos.library/FGets", (V36+) */
/* Copyright 1993, Anders Bjerin, Amiga C Club */
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_LENGTH 80
UBYTE *version = "$VER: FGets 1.1";
int main( int argc, char *argv[] );
int main( int argc, char *argv[] )
{
BPTR my_file;
UBYTE my_buffer[ BUFFER_LENGTH ];
STRPTR ok_ptr;
/* Open an already existing file: */
my_file = Open( "RAM:Shakespeare.doc", MODE_OLDFILE );
if( !my_file )
exit( 20 );
/* Collect the first line: (If the line is longer than */
/* BUFFER_LENGTH, the remaining part will be read next time.) */
ok_ptr = FGets( my_file, my_buffer, BUFFER_LENGTH );
/* As long as we have not reached the end of the file */
/* or have found an error we stay in the while loop: */
while( ok_ptr )
{
/* Print the collected string: */
printf( "%s", my_buffer );
/* Get next line: (Or the remaining part of the */
/* last one if the whole line did not fit in the */
/* buffer the first time.) */
ok_ptr = FGets( my_file, my_buffer, BUFFER_LENGTH );
}
/* EOF or Error? */
if( IoErr() )
printf( "Error while reading!\n" );
else
printf( "End Of File!\n" );
Close( my_file );
exit( 0 );
}